<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>

  <body>
    <button>加载热搜数据</button>
    <button>加载秒杀数据</button>
    <button>加载促销精品数据</button>
    <button>加载排行榜数据</button>

    <div class="main" style="margin-top: 15px"></div>

    <script>
      var oMain = document.querySelector(".main");
      var oBtns = document.querySelectorAll("button");
      let xhr = new XMLHttpRequest();
      oBtns[0].onclick = () => {
        var productSearchAPI = "http://106.52.75.114/api/v2/hot/keywords";
        xhr.open("Get", productSearchAPI);
        xhr.send();
        xhr.onload = function () {
          if (xhr.status == 200) {
            var obj = JSON.parse(xhr.responseText);
            var str = "";
            obj.data.list.forEach((v) => {
              v;
              str += `
                        <div>${v}</div>
                        `;
            });
            document.querySelector(".main").innerHTML = str;
          }
        };
      };

      oBtns[1].onclick = () => {
        var productSearchAPI =
          "http://106.52.75.114/api/seckill/index?page=1&limit=8";
        xhr.open("Get", productSearchAPI);
        xhr.send();
        xhr.onload = function () {
          if (xhr.status == 200) {
            var obj = JSON.parse(xhr.responseText);
            var str = "";
            obj.data.seckillTime.forEach((v) => {
              v;
              str += `
                            <img src="${v.slide}" alt="">
                        `;
            });
            document.querySelector(".main").innerHTML = str;
          }
        };
      };

      oBtns[2].onclick = () => {
        document.querySelector(".main").innerHTML = "";
        var productSearchAPI =
          "http://106.52.75.114/api/home/products?page=1&limit=6&type=5&newsOrder&salesOrder&selectId&selectType=0";
        xhr.open("Get", productSearchAPI);
        xhr.send();
        xhr.onload = function () {
          if (xhr.status == 200) {
            var obj = JSON.parse(xhr.responseText);
            var str = "";
            obj.data.list.forEach((v) => {
              v;
              str += `
                        <div>${v.store_name}</div>
                        `;
            });
            document.querySelector(".main").innerHTML = str;
          }
        };
      };

      oBtns[3].onclick = () => {
        document.querySelector(".main").innerHTML = "";
        var productSearchAPI =
          "http://106.52.75.114/api/home/products?page=1&limit=3&type=7&newsOrder&salesOrder&selectId&selectType=0";
        xhr.open("Get", productSearchAPI);
        xhr.send();
        xhr.onload = function () {
          if (xhr.status == 200) {
            var obj = JSON.parse(xhr.responseText);
            var str = "";
            obj.data.list.forEach((v) => {
              v;
              str += `
                        <div>${v.store_name}</div>
                        `;
            });
            document.querySelector(".main").innerHTML = str;
          }
        };
      };
    </script>
  </body>
</html>
